package com.taobao.snowsnow.web.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.taobao.snowsnow.hibernate.pojo.ProductCollect;
import com.taobao.snowsnow.hibernate.service.ProductCollectService;
import com.taobao.snowsnow.util.ApplicationContextUtil;
import com.taobao.snowsnow.util.Lazy;

public class ShowProductInfo extends TagSupport {
	private static final long serialVersionUID = -4127536032980066486L;

	private int ids;
	private boolean pic;
	private boolean dimension;
	private boolean color;

	private ProductCollectService productCollectService;

	@Override
	public int doStartTag() throws JspException {
		productCollectService = (ProductCollectService) ApplicationContextUtil
				.getBean("ProductCollectService");
		Lazy lazy = new Lazy();
		try {
			ProductCollect productCollect = productCollectService.findById(ids);
			JspWriter out = this.pageContext.getOut();

			if (pic)
				out.print("<img src=\"" + productCollect.getPicUrl() + "_sum.jpg\" />");
		} catch (Exception e) {

			throw new JspException(e.getMessage());

		}
		lazy.close();

		return SKIP_BODY;

	}

	@Override
	public int doEndTag() throws JspException {

		return EVAL_PAGE;

	}

	@Override
	public void release() {
		super.release();
	}

	public int getIds() {
		return ids;
	}

	public void setIds(int ids) {
		this.ids = ids;
	}

	public boolean isDimension() {
		return dimension;
	}

	public void setDimension(boolean dimension) {
		this.dimension = dimension;
	}

	public boolean isColor() {
		return color;
	}

	public void setColor(boolean color) {
		this.color = color;
	}

	public boolean isPic() {
		return pic;
	}

	public void setPic(boolean pic) {
		this.pic = pic;
	}
}
